package com.incar.chuxing.utils.Dialogs;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.incar.chuxing.R;

/**
 * 创建自定义的dialog，主要学习其实现原理
 * Created by Michael Pi  on 2016/3/22.
 */
public class PayResultDialog extends Dialog {


    private String title;//从外界设置的title文本
    private String content;//从外界设置的消息文本
    private int imageId;

    private ImageView resultImage;
    private TextView resultTitle;
    private TextView resultContent;


    public PayResultDialog(Context context) {
        super(context, R.style.MyDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_pay_result_dialog);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        //初始化界面控件
        initView();
        //初始化界面数据
        initData();

    }


    /**
     * 初始化界面控件的显示数据
     */
    private void initData() {
        //如果用户自定了title和message

        if (title != null) {
            resultTitle.setText(title);
        }
        if (content != null) {
            resultContent.setText(content);
        }
        if (imageId != 0) {
            resultImage.setImageDrawable(getContext().getResources().getDrawable(imageId));
        }

    }

    /**
     * 初始化界面控件
     */
    private void initView() {
        resultImage = (ImageView) findViewById(R.id.result_image);
        resultTitle = (TextView) findViewById(R.id.result_title);
        resultContent = (TextView) findViewById(R.id.result_content);
    }


    public void setResultContent(String content) {
        this.content = content;
    }

    public void setResultTitle(String title) {
        this.title = title;
    }

    public void setResultImage(int imageId) {
        this.imageId = imageId;
    }
}
